package com.grass.appointment.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import androidx.exifinterface.media.ExifInterface;
import freemarker.template.Template;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SideBar extends View {
    public String[] INDEX_STRING;
    private int choose;
    private List<String> letterList;
    private TextView mTextDialog;
    private OnTouchingLetterChangedListener onTouchingLetterChangedListener;
    private Paint paint;

    public interface OnTouchingLetterChangedListener {
        void onTouchingLetterChanged(String str);

        void onTouchingLetterChanging(String str);
    }

    public SideBar(Context context) {
        this(context, null);
    }

    public SideBar(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public SideBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.INDEX_STRING = new String[]{"#", ExifInterface.GPS_MEASUREMENT_IN_PROGRESS, "B", "C", Template.DEFAULT_NAMESPACE_PREFIX, ExifInterface.LONGITUDE_EAST, "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", ExifInterface.LATITUDE_SOUTH, ExifInterface.GPS_DIRECTION_TRUE, "U", ExifInterface.GPS_MEASUREMENT_INTERRUPTED, ExifInterface.LONGITUDE_WEST, "X", "Y", "Z"};
        this.choose = -1;
        this.paint = new Paint();
        init();
    }

    private void init() {
        this.letterList = Arrays.asList(this.INDEX_STRING);
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight();
        int width = getWidth();
        int size = height / this.letterList.size();
        for (int i = 0; i < this.letterList.size(); i++) {
            this.paint.setColor(Color.parseColor("#ffb1b1b1"));
            this.paint.setTypeface(Typeface.DEFAULT_BOLD);
            this.paint.setAntiAlias(true);
            this.paint.setTextSize(35.0f);
            if (i == this.choose) {
                this.paint.setColor(Color.parseColor("#e02020"));
                this.paint.setFakeBoldText(true);
            }
            canvas.drawText(this.letterList.get(i), (((float) width) / 2.0f) - (this.paint.measureText(this.letterList.get(i)) / 2.0f), ((float) (size * i)) + (((float) size) / 2.0f), this.paint);
            this.paint.reset();
        }
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        int action = motionEvent.getAction();
        float y = motionEvent.getY();
        int i = this.choose;
        OnTouchingLetterChangedListener onTouchingLetterChangedListener2 = this.onTouchingLetterChangedListener;
        int height = (int) ((y / ((float) getHeight())) * ((float) this.letterList.size()));
        if (action == 1) {
            this.choose = -1;
            invalidate();
            TextView textView = this.mTextDialog;
            if (textView != null) {
                textView.setVisibility(8);
            }
            if (height >= 0 && height < this.letterList.size() && onTouchingLetterChangedListener2 != null) {
                onTouchingLetterChangedListener2.onTouchingLetterChanged(this.letterList.get(height));
            }
        } else if (i != height && height >= 0 && height < this.letterList.size()) {
            TextView textView2 = this.mTextDialog;
            if (textView2 != null) {
                textView2.setText(this.letterList.get(height));
                this.mTextDialog.setVisibility(0);
            }
            this.choose = height;
            invalidate();
            if (onTouchingLetterChangedListener2 != null) {
                onTouchingLetterChangedListener2.onTouchingLetterChanging(this.letterList.get(height));
            }
        }
        return true;
    }

    public void setIndexText(ArrayList<String> arrayList) {
        this.letterList = arrayList;
        invalidate();
    }

    public void setTextView(TextView textView) {
        this.mTextDialog = textView;
    }

    public void setOnTouchingLetterChangedListener(OnTouchingLetterChangedListener onTouchingLetterChangedListener2) {
        this.onTouchingLetterChangedListener = onTouchingLetterChangedListener2;
    }

    public void refresh() {
        init();
        invalidate();
    }
}
